<template>
  <div class="app-container" v-loading="loading">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="会议主题" prop="meetingName">
        <el-input v-model="queryParams.meetingName" placeholder="请输入会议主题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开始日期">
        <el-date-picker type="datetimerange" v-model="queryParams.meetingTime" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 按钮 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="informList">
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="会议主题" align="center" prop="meetingName">
        <template slot-scope="scope" v-hasPermi="['meetingManagement:getInfo']">
          <el-link :underline="false" @click="lookMeeting(scope.row)" type="primary">{{ scope.row.meetingName
            }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="会议开始日期" align="center" prop="meetingStartTime" />
      <el-table-column label="应到人数" align="center" prop="expectedNumber">
        <template slot-scope="scope" v-hasPermi="['meeting:user:list']">
          <el-link :underline="false" @click="lookCheckIn(scope.row, 1)" type="primary">
            {{ scope.row.expectedNumber }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="签到人数" align="center" prop="signInNumber">
        <template slot-scope="scope" v-hasPermi="['meeting:user:list']">
          <el-link :underline="false" @click="lookCheckIn(scope.row, 2)" type="primary">
            {{ scope.row.signInNumber }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="未签到人数" align="center" prop="noSignInNumber">
        <template slot-scope="scope" v-hasPermi="['meeting:user:list']">
          <el-link :underline="false" @click="lookCheckIn(scope.row, 3)" type="primary">
            {{ scope.row.noSignInNumber }}
          </el-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 会议详情对话框 -->
    <el-dialog title="会议详情" :visible.sync="manageOpen" width="600px" center :close-on-click-modal="false">
      <el-form ref="meetingForm" :model="manageForm" label-width="100px">
        <el-form-item label="会议主题" prop="meetingName">
          <div>{{ manageForm.meetingName }}</div>
        </el-form-item>
        <el-form-item label="类型" prop="meetingType">
          <div>{{ selectDictLabel(dict.type.meeting_type, manageForm.meetingType) }}</div>
        </el-form-item>
        <el-form-item label="主持人" prop="meetingCompere">
          <div>{{ manageForm.meetingCompereName }}</div>
        </el-form-item>
        <el-form-item label="开始时间" prop="meetingStartTime">
          <div>{{ manageForm.meetingStartTime }}</div>
        </el-form-item>
        <el-form-item label="结束时间" prop="meetingEndTime">
          <div>{{ manageForm.meetingEndTime }}</div>
        </el-form-item>
        <el-form-item label="实际开始时间" prop="meetingActuallyStartTime">
          <div>{{ manageForm.meetingActuallyStartTime }}</div>
        </el-form-item>
        <el-form-item label="实际结束时间" prop="meetingActuallyEndTime">
          <div>{{ manageForm.meetingActuallyEndTime }}</div>
        </el-form-item>
        <el-form-item label="会议文件" prop="meetingTitle">
          <div style="display: flex;gap: 20px;">
            <el-link v-for="item in manageForm.tbMeetingFile" :key="item.meetingFileUrl" :href="item.meetingFileUrl"
              target="_blank">{{ item.fileName }}</el-link>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancelManage">确 定</el-button>
        <el-button @click="cancelManage">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 签到人数对话框 -->
    <el-dialog :title="signInTitle" :visible.sync="signInOpen" width="500px" center :close-on-click-modal="false">
      <div class="container">
        <el-table :data="signInList">
          <el-table-column label="序号" type="index" align="center" />
          <el-table-column label="姓名" align="center" prop="lastName" />
          <el-table-column label="手机号" align="center" prop="mobile" />
          <el-table-column label="签到时间" align="center" prop="signInTime" />
          <!-- <el-table-column label="签到地点" align="center" prop="signInTime" />
          <el-table-column label="签到类型" align="center" prop="signInTime" /> -->
        </el-table>
        <!-- 分页 -->
        <pagination v-show="signInTotal > 0" :total="signInTotal" :page.sync="querySignIn.pageNum"
          :limit.sync="querySignIn.pageSize" @pagination="getSignInData" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancelSignIn">确 定</el-button>
        <el-button @click="cancelSignIn">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getSignInNumberList, getSignInList } from "@/api/meeting/inform";
import { manageInfo } from "@/api/meeting/manage";

export default {
  name: "Inform",
  dicts: ['meeting_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会议通知表格数据
      informList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        meetingName: null,
        meetingTime: [],
        meetingStartTime: null,
        meetingEndTime: null,
      },
      // 是否显示会议详情
      manageOpen: false,
      // 会议详情
      manageForm: {},
      // 是否显示签到人数弹出层
      signInOpen: false,
      // 签到人数弹出层标题
      signInTitle: '',
      // 签到人员名单搜索条件
      querySignIn: {
        meetingName: null,
        meetingSerial: null,
        type: 2,
        pageNum: 1,
        pageSize: 10
      },
      // 签到人员分页
      signInTotal: 0,
      // 签到人员名单
      signInList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会议通知列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.meetingTime && this.queryParams.meetingTime.length > 0) {
        this.queryParams.meetingStartTime = this.queryParams.meetingTime[0]
        this.queryParams.meetingEndTime = this.queryParams.meetingTime[1]
      }
      getSignInNumberList(this.queryParams).then(response => {
        this.informList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看会议详情
    lookMeeting(row) {
      manageInfo({ meetingId: row.meetingId }).then(res => {
        res.tbMeetingFile && res.tbMeetingFile.forEach(item => {
          item.name = item.fileName
        });
        this.manageForm = res.data
        this.manageOpen = true
      })
    },
    // 会议详情取消按钮
    cancelManage() {
      this.manageOpen = false
    },
    // 查看签到情况
    lookCheckIn(row, type) {
      this.querySignIn = {
        meetingName: row.meetingName,
        meetingSerial: row.meetingSerial,
        type: type,
        pageNum: 1,
        pageSize: 10
      }
      switch (type) {
        case 1: this.signInTitle = '应到人数'
          break;
        case 2: this.signInTitle = '签到人数'
          break;
        case 3: this.signInTitle = '未签到人数'
          break;
      }
      this.getSignInData()
      this.signInOpen = true;
    },
    // 签到人数取消按钮
    cancelSignIn() {
      this.signInOpen = false;
    },
    // 查询签到名单
    getSignInData() {
      getSignInList(this.querySignIn).then(res => {
        this.signInList = res.rows
        this.signInTotal = res.total
      })
    },
  }
};
</script>
